package copyfile;

import java.io.*;

public class RecursiveFileCopier {
    public void copyDirectory(File source, File target) throws IOException {
        File[] files = source.listFiles();

        if (files != null) {
            for (File file : files) {
                File destFile = new File(target, file.getName());

                if (file.isDirectory()) {
                    copyDirectory(file, destFile);
                } else if (!file.getName().endsWith(".java")) {
                    copyFile(file, destFile);
                }
            }
        }
    }

    private void copyFile(File sourceFile, File destFile) throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourceFile));

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));

        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        bis.close();
        bos.close();

        System.out.println("文件复制: " + sourceFile + " -> " + destFile);
    }
}



